package com.travelbug.io;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 字节输入流
 */
public class FileInputStreamTest {


    @Test
    public void testFileInputStream() {
        //创建文件对象
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            File src = new File("hello.txt");
            File des = new File("hello-travelbug.txt");

            fis = new FileInputStream(src);
            fos = new FileOutputStream(des);

            byte[] buffer = new byte[5];
            int len = 0;
            while ((len = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
